﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AISFMIOperator
{
    public partial class AddProviderForm : Form
    {
        public AddProviderForm()
        {
            InitializeComponent();
            RefreshAllData();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void RefreshAllData()
        {
            this.citycomboBox5.DataSource = City.GetAllCities();
            this.citycomboBox5.DisplayMember = "CityFullName";

            this.specialty.DataSource = Specialty.GetAllSpecialties();
            this.specialty.DisplayMember = "SpecialtyName";
        }

        private void AddProviderForm_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Address a = new Address();
            a.AddressID = 0;
            a.Addr = address.Text;
            a.City = (City)citycomboBox5.SelectedItem;
            a.PostIndex = int.Parse(postindex.Text.Trim());

            a.Save();

            Provider p = new Provider();
            p.ProviderID = 0;
            p.LastName = lastnametextBox2.Text.Trim();
            p.FirstName = firstnametextBox1.Text.Trim();
            p.MiddleName = middletextBox3.Text.Trim();
            p.Specialty = (Specialty)specialty.SelectedItem;
            p.ContactPhone = phonetextBox8.Text.Trim();
            p.Email = emailtextBox9.Text.Trim();


            p.Address = a;

            p.Save();

            this.Close();

        }
    }
}
